<template>
    <div class="conHeader-box not-print">
        <div class="conHeader">
            <div class="address-text" @click.stop="getParentFun" v-if="!$root.$data.is_szy">
                <div class="address-title">{{getComputedView ? '申领科室：' : '默认起点：'}}</div><span :title="startAddress" class="address">{{ startAddress }}</span>
            </div>
            <!-- 二级菜单 -->
            <div class="second-nav">
                <div :class="['nav-item',v.active ? 'nav-active' : '']" v-for="(v,i) in currSecondNav" :key="i" @click="secondNavView(v)">
                    <span>{{v.name}}</span>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import store from '../store/index';
export default {
    props:{
        currView:'', // 页面名称 引入的组件名称
        startAddress:'', // 起点地址
        isOpenCloth:'' // 是否开通被服功能
    },
    data(){
        return{
            isHIS:false,
            nav:[],
            currSecondNav:[], // 当前显示的二级菜单
            isSixthHospital: Cookies.get("categoryid") == 17 || Cookies.get("categoryid") == 19
        }
    },
    computed:{
      getComputedView(){
        return ['view_8', 'view_13', 'view_14'].includes(this.currView)
      }
    },
    watch:{
        currView(n,s){
            console.log(123,n,s);
            this.inits()
        }
    },
    methods:{
        getParentFun(){
            this.$parent.navClickFn(4)
        },
        secondNavView(data){
            if(this.currSecondNav.length>0){
                this.currSecondNav.map(res=>{
                    if(data.currView == '故障排除'){
                        this.$emit('updateTroubleShooting')
                        return
                    }
                    res.active = ''
                    if(res.hasOwnProperty('key')){ // 有key这个字段时，二级导航父元素为查看栏
                        if(res.name == data.name){
                            res.active = 'active'
                            this.$emit('updateLisNavTab',res.key)
                            return
                        }
                    }
                    if(res.currView == data.currView){
                        res.active = 'active'
                        var currViewNum = data.currView.split('_')[1]
                        this.$emit('updateView',currViewNum)
                    }
                })
            }

        },
        inits(){
            
            this.$root.$data.cid = Cookies.get("categoryid");
            if (["17", "19", "28"].indexOf(this.$root.$data.cid) != -1) { // 判断医院是否开通HIS
                this.isHIS = true;
            } else {
                this.isHIS = false;
            }
            this.nav = [ 
                {currView:'view_10',name:'服务受理',secondNav:[{currView:'view_10',name:'详细下单',active:''}]},
                {currView:'view_1',name:'输送下单',secondNav:[{currView:'view_1',name:'详细下单',active:''},
                    {currView:'view_2',name:'快捷下单',active:''}
                ]},
                {currView:'view_15',name:'医废确认',secondNav:[
                    {currView:'view_15',name:'按日查询',active:''},
                    {currView:'view_16',name:'按月查询',active:''},
                    {currView:'view_17',name:'详细查询',active:''},
                    {currView:'view_18',name:'质控留痕',active:''},
                    {currView:'view_19',name:'图形汇总',active:''},
                ]},
                {currView:'view_8',name:'医用织物',secondNav:[]},
                {currView:'view_3',name:'查看',secondNav:[{ currView:'view_3',name: '输送单', key: 'trans',active:'' }]}, // 开通了被服 查看就有被服申领单，设置有被服设置
                {currView:'view_4',name:'设置',secondNav:[{currView:'view_4',name:'起点设置',active:''},{currView:'view_6',name:'下单指南',active:''}]},
            ]
            if(store.state.hwConfig && store.state.hwConfig.hw_hwtag  && store.state.hwConfig.hw_hwtag == 1){
                this.nav.forEach(item => {
                    if(item.name == '医废确认'){
                        item.secondNav = [
                            {currView:'view_15',name:'按日查询',active:''},
                            {currView:'view_16',name:'按月查询',active:''},
                            {currView:'view_17',name:'详细查询',active:''},
                            {currView:'view_18',name:'质控留痕',active:''},
                            {currView:'view_19',name:'图形汇总',active:''},
                            {currView:'view_20',name:'标签申领',active:''}
                        ]
                    }
                    
                });
            }
            if(this.isHIS){this.nav[1].secondNav.push({currView:'view_5',name: this.$root.$data.cid == "19" ? "医嘱单" : "HIS" ,active:''})}
            var flag = false
            // 查看栏 根据医院id隐藏显示
            if(this.$root.$data.wxCid.indexOf(this.$root.$data.cid) != -1 || this.$root.$data.cid == '15' || this.$root.$data.cid == '33' ){
                var tabList =  [
                    { currView:'view_3',name: '输送单', key: 'trans',active:'' },
                    { currView:'view_12',name: this.$root.$data.cid != '33' ? '维修单' : '服务受理单', key: 'mtain',active:'' },
                ]
                if(this.$root.$data.cid != '15' && this.$root.$data.cid != '33'){
                    tabList[0].active = 'active'
                    this.$emit('updateLisNavTab',tabList[0].key)
                }else {
                    tabList[1].active = 'active'
                    this.$emit('updateLisNavTab',tabList[1].key)
                }
                this.nav[3].secondNav = tabList
                flag = true
            }
            if(this.isOpenCloth){ // 当开通被服功能时
                flag = true
        //    this.nav[4].secondNav.splice(1,0,{currView:'view_14',name:'被服设置',active:''})
                for(let i=0;i<this.nav[3].secondNav.length;i++){
                    this.nav[3].secondNav[i].active = ''
                }
                var obj = { currView:'view_13',name: '医用织物申领', key: 'cloth',active:'active' }
                this.$emit('updateLisNavTab','cloth')
                this.nav[4].secondNav.push(obj)
            }
            console.log(this.nav[4]);
            if(this.currView == 'view_3'  || this.currView == 'view_12' || this.currView == 'view_13'){

                if(!flag) this.nav[4].secondNav[0].active = 'active'
                this.currSecondNav = this.nav[4].secondNav
                return
            }
            // 设置栏 故障排除判断
            if(this.isSixthHospital){
                this.nav[4].secondNav.push({currView:'故障排除',name:'故障排除',active:''})
            }
            for(let i=0;i<this.nav.length;i++){

                this.nav[i].secondNav.map((m,n)=>{
                    m.active = ''
                    console.log(m);
                    if(m.currView == this.currView){
                        m.active = 'active'
                        this.currSecondNav = this.nav[i].secondNav
                    }

                })
            }
            
        }
    },
    mounted(){

       setTimeout(_=>{this.inits()},300)


    }
}
</script>

<style>

</style>
